/**
 * @file pt_ui_pageman.h
 * @brief 
 * @author yejiahao
 * @date 2023-11-07 18:38:58
 * 
 * @copyright Copyright (c) 2023 by 深圳市鹏天微智能科技有限公司, All Rights Reserved.
 */

#ifndef __PT_UI_PAGEMAN_H__
#define __PT_UI_PAGEMAN_H__

#include "lvgl.h"
#include "pt.h"

#ifdef __cplusplus
extern "C" {
#endif

struct pt_ui_page_context
{
    lv_obj_t *page_root;
    pt_list_t widgets;
    void *user_data;    /*!< 通常存放每个界面的 item 数组 */
};
typedef struct pt_ui_page_context pt_ui_page_context_t;

struct pt_ui_page_operation
{
    uint16_t user_data_size;
    void (*create)(struct pt_ui_page_context* ctx, void *arg);
    void (*destroy)(struct pt_ui_page_context* ctx);
    void (*will_disappear)(struct pt_ui_page_context* ctx);
    void (*will_appear)(struct pt_ui_page_context* ctx);
};
typedef struct pt_ui_page_operation *pt_ui_widget_op_t;

struct pt_ui_page_info
{
    pt_list_t node;
    uint32_t page_uid;
    struct pt_ui_page_context ctx;
    lv_group_t *group;
    const struct pt_ui_page_operation *op;
};
typedef struct pt_ui_page_info pt_ui_widget_info_t;

void pt_ui_page_init(void);
uint32_t pt_ui_page_load(const struct pt_ui_page_operation *page, const void *arg);
void pt_ui_page_goback(void);
void pt_ui_page_goback_root(void);
void pt_ui_page_load_widget(struct pt_ui_page_context* ctx, const struct pt_ui_page_operation *widget_op, void *arg);

void pt_ui_page_subscribe(int topic_id, pt_mbus_callback_t cbk, void *user_data);
bool pt_ui_page_is_top_by_op(const struct pt_ui_page_operation *op);
bool pt_ui_page_is_top_by_id(uint32_t id);
bool pt_ui_page_instack(uint32_t id);

#ifdef __cplusplus
}
#endif

#endif /* __PT_UI_PAGEMAN_H__ */
